package com.itboye.jmsfhz.data.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;
import com.itboye.jmsfhz.data.interfaces.IWxPay;
import com.itboye.jmsfhz.data.model.PersonDataBean;
import com.itboye.jmsfhz.data.model.WePayModel;
/***
 * 微信相关
 * @author admin
 *
 */
public class WxPayRepository extends BaseNetRepository implements
		IWxPay<WePayModel> {
	public static final String WxPay = "BY_WxpayApp_preOrder";//8.2 微信预支付
	public static final String WxLogin="BY_Weixin_login";//2.8 微信登陆
	public static final String WxBind="BY_Weixin_bind";// 2.11 微信绑定
	@Override
	public void add(WePayModel model) {
		// TODO Auto-generated method stub
				
	}

	@Override
	public void delete(WePayModel model) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(WePayModel model) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getInfo(WePayModel model) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<WePayModel> query(WePayModel model) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 *2.11 微信绑定
	 * 
	 */
	@Override
	public void bindWx(String code,String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
		params.put("uid",uid);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(WxLogin, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<String>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}
	/**
	 *  2.8 微信登陆
	 */
	@Override
	public void loginByWx(String code) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<PersonDataBean>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
		(new Builder<PersonDataBean>())
				.setTypeVerParamsAndReturnClass(WxLogin, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<PersonDataBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}
	/***
	 * 10.2 微信预支付
	 */
	@Override
	public void wxPay(String code,String totalPrice,String desc) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<WePayModel>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
//		params.put("total_price", totalPrice);
//		params.put("desc", desc);
		(new Builder<WePayModel>())
				.setTypeVerParamsAndReturnClass(WxPay, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<WePayModel>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}


}
